import processing.core.PImage;


/**
 * Displays the title screen, and handles the user input on selecting the game params.
 * 
 * @author ben
 *
 */
public class TitleScreen extends Screen {
	
	PImage numPlayerImg[];
	int imgGap = 40;
	int imgX[], imgY[];
	int highlight; // which icon to highlight?
	
	public TitleScreen(Carcassonne c)
	{
		super(c);	
	
		int totalWidth = 2*imgGap;
		numPlayerImg = new PImage[3];
		imgX = new int[3];
		imgY = new int[3];
		for(int i=0;i<=2;i++)
		{
			numPlayerImg[i] = theme.getNumPlayerSelection(2+i);
			totalWidth += numPlayerImg[i].width;			
		}
		
		imgX[0] = (width - totalWidth)/2;
		imgY[0] = height - numPlayerImg[2].height;
		
		for(int i=1;i<=2;i++)
		{
			imgX[i] = imgX[i-1]+numPlayerImg[i-1].width+imgGap;
			imgY[i] = imgY[i-1];
		}
		
		highlight = -1;
	}
	
	public void draw()
	{
		for(int i=0;i<=2;i++)
		{
			if (i==highlight)
				c.tint(255,255,255);
			else c.tint(155,155,155);
			
			c.image(numPlayerImg[i],imgX[i],imgY[i]);
		}
	}
	
	public boolean mousePressed(int x, int y)
	{
		for(int i=0;i<=2;i++)
		{
			if (x >= imgX[i] && x <= imgX[i]+numPlayerImg[i].width &&
				y >= imgY[i] && y <= imgY[i]+numPlayerImg[i].height)
			{
				Carcassonne.NUMPLAYERS = 2+i;
				return true;
			}
		}
		
		return false;		
	}
	
	public boolean mouseMoved(int x, int y)
	{
		for(int i=0;i<=2;i++)
		{
			if (x >= imgX[i] && x <= imgX[i]+numPlayerImg[i].width &&
				y >= imgY[i] && y <= imgY[i]+numPlayerImg[i].height)
			{
				highlight = i;
				return true;
			}
		}
		highlight = -1;		
		return false;		
	}
	

}
